<template>
<div class="app-container">
  <el-form :inline="true" :model="formInline" class="demo-form-inline">
  <el-form-item label="举报人">
    <el-input clearable size="small" v-model="formInline.userNiceName" placeholder="请输入举报人"></el-input>
  </el-form-item>
  <el-form-item label="被举报人">
    <el-input clearable size="small" v-model="formInline.targetNickName" placeholder="请输入被举报人"></el-input>
  </el-form-item>
  <el-form-item label="举报时间">
    <el-date-picker
      v-model="formInline.reportDate"
      type="date"
      size="small"
      value-format="yyyy-MM-dd"
      placeholder="选择举报时间">
    </el-date-picker>
  </el-form-item>
  <el-form-item>
    <el-button size="small" type="primary" @click="fetchData">查询</el-button>
    <el-button size="small" @click="reset">重置</el-button>
  </el-form-item>
</el-form>
  <el-table ref="multipleTable" v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row empty-text="暂无数据">
    <el-table-column label="ID" width="80">
      <template slot-scope="scope">
        {{ scope.row.id }}
      </template>
    </el-table-column>
    <el-table-column label="举报人昵称" width="150">
      <template slot-scope="scope">
        {{ scope.row.nickName }}
      </template>
    </el-table-column>
    <el-table-column label="被举报人昵称" width="150">
      <template slot-scope="scope">
        {{scope.row.targetNickName}}
      </template>
    </el-table-column>
    <el-table-column label="被举报主贴ID" width="110">
      <template slot-scope="scope">
        <el-tag @click="goTie(scope.row)" size="small" style="cursor:pointer;">{{ scope.row.targetId }}</el-tag>
      </template>
    </el-table-column>
    <el-table-column :show-overflow-tooltip="true" label="举报描述">
      <template slot-scope="scope">
        <span>{{ scope.row.detail }}</span>
      </template>
    </el-table-column>
    <el-table-column label="举报时间" width="180">
      <template slot-scope="scope">
        <span>{{ scope.row.createTime }}</span>
      </template>
    </el-table-column>
    <el-table-column label="处理状态" width="120">
      <template slot-scope="scope">
        <el-tag v-if="scope.row.dealStatus == 0" size="small" type='danger'>未处理</el-tag>
        <el-tag v-else size="small" type='success'>已处理</el-tag>
      </template>
    </el-table-column>
    <el-table-column :show-overflow-tooltip="true" label="处理结果">
      <template slot-scope="scope">
        {{ scope.row.dealResult }}
      </template>
    </el-table-column>
    <el-table-column fixed="right" label="操作" width="100">
      <template slot-scope="scope">
        <el-button type="text" style="color:#ff0000;" v-if="scope.row.dealStatus == 0" @click="openJubaoModal(scope.row)">处理</el-button>
        <el-divider v-if="scope.row.dealStatus == 0" direction="vertical"></el-divider>
        <el-popconfirm
          @onConfirm="del(scope.row)"
          confirm-button-text='确定'
          cancel-button-text='取消'
          icon="el-icon-info"
          icon-color="red"
          title="是否删除本条数据？">
          <el-button  slot="reference" type="text" style="color:#ff0000;">删除</el-button>
        </el-popconfirm>
      </template>
    </el-table-column>
  </el-table>
  <div style="margin:10px 0 0 0;text-align:right;">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageObj.pageNum"
      :page-sizes="[10, 30, 50, 100]"
      :page-size="pageObj.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageObj.total">
    </el-pagination>
  </div>

  <el-dialog title="处理结果" :visible.sync="dialogFormVisible">
    <el-form :model="form">
      <el-form-item label="处理结果" :label-width="formLabelWidth">
        <el-input type="textarea" :rows="5" v-model="form.result" autocomplete="off" placeholder="请输入处理结果"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="closeModal">取 消</el-button>
      <el-button type="primary" @click="confirmJubao">确 定</el-button>
    </div>
  </el-dialog>
</div>
</template>

<script>
import {
  getReportListApi,
  reportSaveApi,
  deleteReportApi
} from '@/api/forum'

export default {
  data() {
    return {
      list: [],
      listLoading: true,
      currentPage: 1,
      formInline: {
        userNiceName: '',
        targetNickName: '',
        reportDate: ''
      },
      dialogFormVisible: false,
      form: {
        result: '',
      },
      formLabelWidth: '80px',
      pageObj: {
        pageSize: 10,
        pageNum: 1,
        total: 0
      },
      jubaoId: '',
      dealStatus: '',
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    reset() {
      this.pageObj.pageSize = 10
      this.pageObj.pageNum = 1
      this.formInline.userNiceName = ''
      this.formInline.targetNickName = ''
      this.formInline.reportDate = ''
      this.fetchData()
    },
    goTie(row) {
      this.$router.push({
        path: '/forum/list',
        query: {
          tid: row.targetId
        }
      })
    },
    del(row) {
      deleteReportApi({
        ids: row.id
      }).then((res) => {
        this.fetchData()
      })
    },
    openJubaoModal(row) {
      this.jubaoId = row.id
      this.dealStatus = row.dealStatus
      this.dialogFormVisible = true
    },
    closeModal() {
      this.dialogFormVisible = false
      this.form.result = ''
    },
    confirmJubao() {
      reportSaveApi({
        id: this.jubaoId,
        dealStatus: 1,
        dealResult: this.form.result
      }).then(response => {
        this.$message.success('操作成功！');
        this.closeModal()
        this.fetchData()
      })
    },
    fetchData() {
      this.listLoading = true
      getReportListApi({
        userNiceName: this.formInline.userNiceName,
        targetNickName: this.formInline.targetNickName,
        reportDate: this.formInline.reportDate,
        pageNum: this.pageObj.pageNum,
        pageSize: this.pageObj.pageSize,
        targetType: 0,
        type: 'thread',
      }).then(response => {
        this.list = response.data.result
        this.listLoading = false
        this.pageObj.total = response.data.total
      })
    },
    handleSizeChange(val) {
      this.pageObj.pageSize = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.pageObj.pageNum = val
      this.fetchData()
    }
  }
}
</script>
